package com.joyxy.spider.mapscript.operation;

/**
 * 垂直移动操作
 * 操作数: 2
 * 参数: XMin/XMax/YMin/YMax/Y/Key
 */
public class VerticalMoveOperation extends BaseOperation {
    /** 执行区域最小横坐标 */
    private int xMin;
    /** 执行区域最大横坐标 */
    private int xMax;
    /** 执行区域最小纵坐标 */
    private int yMin;
    /** 执行区域最大纵坐标 */
    private int yMax;
    /** 目标位置纵坐标 */
    private int targetY;
    /** 移动模式: 0-锁定纵坐标, 1-向上爬到顶, 2-到达位置停止锁定纵坐标 */
    private int moveMode;
    
    public VerticalMoveOperation(int xMin, int xMax, int yMin, int yMax, int targetY, int moveMode) {
        super(2, "垂直移动");
        this.xMin = xMin;
        this.xMax = xMax;
        this.yMin = yMin;
        this.yMax = yMax;
        this.targetY = targetY;
        this.moveMode = moveMode;
    }
    
    /**
     * 从参数数组创建垂直移动操作
     */
    public static VerticalMoveOperation fromParameters(int[] parameters) {
        if (parameters == null || parameters.length < 6) {
            throw new IllegalArgumentException("垂直移动操作需要6个参数: XMin/XMax/YMin/YMax/Y/Key");
        }
        return new VerticalMoveOperation(parameters[0], parameters[1], parameters[2], parameters[3], parameters[4], parameters[5]);
    }
    
    @Override
    public void execute() {
        String modeDesc = getModeDescription();
        System.out.println("执行垂直移动: 在区域(" + xMin + "," + yMin + ")-(" + xMax + "," + yMax + 
                         ") 移动到Y=" + targetY + ", 模式: " + modeDesc);
        // 这里应该调用实际的移动逻辑
    }
    
    @Override
    public boolean isValid() {
        return xMin <= xMax && yMin <= yMax && targetY >= 0 && moveMode >= 0 && moveMode <= 2;
    }
    
    @Override
    public String getDetailInfo() {
        return String.format("垂直移动: 执行区域(%d,%d,%d,%d) → 目标Y坐标=%d, 模式=%s", 
                xMin, xMax, yMin, yMax, targetY, getModeDescription());
    }
    
    /**
     * 获取移动模式描述
     */
    public String getModeDescription() {
        switch (moveMode) {
            case 0: return "锁定纵坐标";
            case 1: return "向上爬到顶";
            case 2: return "到达位置停止锁定纵坐标";
            default: return "未知模式";
        }
    }
    
    /**
     * 检查指定坐标是否在执行区域内
     */
    public boolean isInExecutionArea(int x, int y) {
        return x >= xMin && x <= xMax && y >= yMin && y <= yMax;
    }
    
    // Getter methods
    public int getxMin() { return xMin; }
    public int getxMax() { return xMax; }
    public int getyMin() { return yMin; }
    public int getyMax() { return yMax; }
    public int getTargetY() { return targetY; }
    public int getMoveMode() { return moveMode; }
    
    @Override
    public String toString() {
        return String.format("VerticalMove{area=(%d,%d,%d,%d), targetY=%d, mode=%d}", 
                xMin, xMax, yMin, yMax, targetY, moveMode);
    }
} 